<?php

class demoCtrl extends Ctrl{

    use demoTrait;

    function test3Act(){
        $data = ['act'=>__function__, 'msg'=>'@root.方法3'];
        $this->tpl($data, 'html2');
    }

    function wwork1Act(){

        //$wework = read('wework', 'ex');
        include_once(DIR_VENDOR . "/wwapi/api/src/CorpAPI.class.php"); 
        
        //$CorpId = read('CorpId');
        $agentId = 'AppAB'; //dump($agentId);
        $api = new CorpAPI();

        $res = $api->DepartmentList(null, 1);
        foreach ($res['department'] as $k => $row) {
            echo "$k: $row[id] : $row[name] : $row[parentid] <br>\n";
        }
        #dump($res);
        echo "<br>\n";


        $res = $api->userSimpleList(1, 1, 1);
        foreach ($res['userlist'] as $k => $row) {
            echo "$k: $row[name] : $row[userid] : ".implode(',', $row['department'])."<br>\n";
        }
        #dump($res);

        #$res = $api->UserList(1, 1, 1);
        #dump($res);

        $uid = 'PeaceXie'; // XieYongShun,PeaceXie,DengJingXiang,ChenZhongHong,
        $res = $api->GetUserById($uid);
        dump($res);

        die();
    }

    function wwmsgSendAct(){

        $act = uval('act','tip');
        $agentId = 'AppAB';
        $acts = [
            '0' => '请处理',
            '1' => '请(加急)处理',
            'tip' => '提到了您',
            'remind' => '工单时间提醒：'.(empty($row['remind_time'])?'':$row['remind_time']),
            'exqa' => '有新评论',
            'bozfa' => '滚筒圆弧R半径计算',
        ];
        $acmsg = isset($acts[$act]) ? $acts[$act] : $act;
        $row = ['did'=>'123456','title'=>"(Test)$acmsg"];
        $premsg = Basic::isLocal() ? '本地测试•' : '';
        // msg
        $des = "<div class=\"gray\">".date('Y-m-d H:i:s')."</div> <div class=\"normal\">工单[$row[did]]{$acmsg}</div><div class=\"highlight\">状态：[$act]</div>";
        $url = "http://192.168.1.253/index/home-envTest?msg=" . $acmsg;
        $msg = ['title'=>"{$premsg}$row[title]", 'des'=>$des, 'url'=>$url, 'btntxt'=>'查看详情'];
        // 
        $touids = ['PeaceXie'];
        $to = ['uids'=>$touids, 'party'=>[], 'tag'=>[]]; 
        $res = extWework::smsgCard($agentId, $msg, $to); 
        dump($msg); dump($res); 
        die("<hr>act=0,1,tip,remind,exqa,bozfa");
    }

    function tmp1Act(){
        $res = [];

        //_keep-base64-icon-test.txt
        $res['ex_wwork'] = read('ex_wwork'); 
        return $this->api($res);


        $up = new Upload();
        $res = [];
        $res['t1'] = $up->getRes();

        $b64data = file_get_contents(DIR_DATA.'/uptemp/_keep-base64-icon-test.txt');
        #$up->upBase64(trim($b64data));
        $res['t3'] = $up->getRes();

        $this->api($res);
        return;

        // '123456789abcdfghjkmnpqrstuvwxy'); // - 0e + iloz
        // 23456789abcdefghjkmnpqrstuvwxy // 01
        $str = '23456789abcdefghjkmnpqrstuvwxy';
        #echo strtoupper($str); echo ':::'.strlen($str); dei();
        // 23456789ABCDEFGHJKMNPQRSTUVWXY // 30 01IL0Z

        $this->tpl();
    }

    function b64Act(){
        $s1 = b64Rnd('1'); $s2 = b64Rnd($s1,1);  echo("<br>$s2 -=> $s1");
        $s1 = b64Rnd('_'); $s2 = b64Rnd($s1,1);  echo("<br>$s2 -=> $s1");
        $s1 = b64Rnd('.'); $s2 = b64Rnd($s1,1);  echo("<br>$s2 -=> $s1");
        //''
        $s1 = b64Rnd('192.168.1.15');     $s2 = b64Rnd($s1,1);  echo("<br>$s2 -=> $s1");
        $s1 = b64Rnd('mysql_boz218');     $s2 = b64Rnd($s1,1);  echo("<br>$s2 -=> $s1");
        $s1 = b64Rnd('qGLzqF6rFlzoSklS'); $s2 = b64Rnd($s1,1);  echo("<br>$s2 -=> $s1");
    }



}

/*
192.168.1.15:1EjLx4CO2EjLykTCM
mysql_boz218:4EjM69mYfxWczlXUEb
qGLzqF6rFlzoSklS:wUst2UvpHbGJnNGFneMdUJ9WXKc
*/

/*

use imcat\basEnv;
use imcat\basOut;
use imcat\basKeyid;
use imcat\comCookie;
use imcat\extWework;
use imcat\glbError;
use imcat\glbHtml;
use imcat\usrMember;
use imcat\vopTpls;
use imcat\vopApi;
use imcat\comConvert;


use imcat\vopApi as api;


class debugCtrl extends uioCtrl{
    
    #public $ucfg = array();
    #public $vars = array();

    function __construct($ucfg=array(), $vars=array()){
        parent::__construct($ucfg, $vars);
        //$this->init($ucfg, $vars);
    }

    function homeAct(){
        $res = $this->re; // ['vars']
        $setTpl = req('setTpl');
        if($setTpl){
            $res['newtpl'] = 'base:home/update';
        }
        return $res;
    }


    function t215Act(){

        $t1 = md5('abc'); dump($t1);
        $t1 = sha1('123'); dump($t1);
        $t1 = hash('ripemd128','test'); dump($t1);

        global $_cbase;
        $t1 = comConvert::sysPass('name', 'pass', 'adminer'); dump("pass1=$t1");
        $t1 = comConvert::sysPass('abcd', '1234', 'abc'); dump("pass2=$t1");
        die();
    }

    function t822Act(){
        echo "view = [close, nodie, ajax]"; 
        $view = $this->ucfg['view']; echo "<hr>";
        if($view=='close'){
            vopTpls::cinc("base:stpl/close_info",1);
        }elseif($view=='ajax'){
            vopTpls::cinc("base:stpl/err_ajax",1);
        }elseif($view=='nodie'){
            define('ERR_NODIE', 1);
            $ra = $this->t822aAct();
            echo("\n\n");
            $rb = $this->t822bAct();
            die("\n\n.end.\n\n");
        }
        
        die();

    }

    function t822aAct(){
        $re = $this->re; 
        $res['a'] = 'a';
        $res['_null'] = $re['vars']['null'];
        return api::v($res, 'api');
    }
    function t822bAct(){
        $re = $this->re;
        $res['b'] = 'b';
        $res['_umods'] = $re['vars']['umods'];
        return api::v($res, 'api');
    }

    function t821Act(){

        echo "view = [err, ex, die]"; 
        $view = $this->ucfg['view']; echo "<hr>";

        if($view=='err'){
            set_error_handler("error_handler_ys");
            $aa = 232332/0;
            //if(($id=-1)<0){ trigger_error("$id<0"); }
            die('.err.');
        }elseif($view=='ex'){
            set_exception_handler('except_handler_ys');
            glbError::show('throw Except...', 'myError');
        }elseif($view=='die'){
            register_shutdown_function('shutdown_handler_ys');
            //CallNotExistFunc321();
            die('.die@.view');
        }elseif($view=='t22'){
            $arr = [1,2];
            #\imcat\glbError::show('throw Except...', 'myError');
            try{
                #file_get_contents('./aas/bbb/.txt');
                //$db = db($arr); 
                //caaal();
                $a = 222/10;
                //$b = $this->aaaa;
                //$db->table('aaa')->data([1,2])->update(1);
            }catch(Exception $ex1){
                vopApi::verr($ex1); 
            }
            die('33');
        }

        //die('.');
    }

    function initDebug(){
        global $_cbase;
        //
    }

    function httpAct(){
        global $_cbase;
        $re = []; //$_GET;
        // data
        $re['ckey'] = $this->rlog['ckey']; 
        $re['server'] = $_SERVER["SERVER_NAME"]; 
        $re['name'] = $_cbase['sys_name'];
        $re['time'] = date('H:i:s'); //basKeyid::kidTemp();
        $re['sid'] = session_id();
        //$re['arr'] = ['a1'=>'b1','a2'=>'b2'];
        // dallow
        $dallow = req('dallow');
        if($dallow){
            $alp = '*'; glbHtml::dallow($alp);
        }
        // return;
        return api::view($re);
    }

    function t315Act(){

        $wework = read('wework', 'ex');
        $CorpId = $wework['CorpId'];
        $jiaSecret = $wework['JiaSecret'];
        $agentId = 'AppAB'; 

        $arts = [
            [
                'title' => '311a-测试节礼品领取1',
                'description' => 'Detail.今年XXX节公司有豪礼相送1',
                'url' => 'https://weapi.zo-ko.com/wework.php/home-cover',
                'picurl' => 'https://wwcdn.weixin.qq.com/node/wwnl/wwnl/style/images/independent/index/Feature2$cc4a42e7.png',
            ]
        ];
        $to = [
            'pids' => ["aeed2a5328e801c54a433b49b1a4e456", "xxxewwewe1221212a", "xxxewwewe1221212b"],
            'sids' => ["77297f459ff475ab22fe1643ae4501d2", "d37a5ea521ac0eb43ede69df77d0046d"],
            //'part' => [6129, ],
            'toall' => 0,
        ];
        $res = extWework::smsgExtNews($agentId, $arts, $to); dump($res); die();

        echo "<hr>";

        // 测试1琪:77297f459ff475ab22fe1643ae4501d2, 测试2鳞:d37a5ea521ac0eb43ede69df77d0046d
        // 3叔/4伯: aeed2a5328e801c54a433b49b1a4e456, 6姨:fbe853d58575e04f7cb974082290ff77
        // 老师: Adm22,Tch36,XieGezi

        foreach (['77297f459ff475ab22fe1643ae4501d2','d37a5ea521ac0eb43ede69df77d0046d',
            'aeed2a5328e801c54a433b49b1a4e456','fbe853d58575e04f7cb974082290ff77'] as $uk) {
            $res = extWework::getEduUser($uk); dump($res);
        }
        echo "<hr>";
        foreach (['Adm22','Tch36','XieGezi'] as $uk) {
            $agsec = $wework['TxlSecret']; // $agentId, $wework['TxlSecret']
            $res = extWework::getUser($uk); dump($res);
        }

        echo "<hr>";

        $layc = [
            '5' => "@ ", // `　`, &nbsp;
            '4' => "# ",
            '3' => "　 * ",
            '2' => "　　 - ",
            '1' => "　　　 - ",
        ];
        if(req('act')=='upd'){
            $r1 = extWework::updEduTab('deps', $agentId); dump($r1);
            $r1 = extWework::updEduTab(4, $agentId); dump($r1);
        }else{
            $r1 = extWework::getEduTabs('deps', $agentId); //dump($r1);
            echo "<b>班级</b>: id, 名称, pid<br>\n";
            foreach($r1 as $k0=>$row){
                echo $layc[$row['type']] . "$row[id] : $row[name] : $row[parentid]";
                echo empty($row['open_group_chat']) ? ', ' : "@$row[open_group_chat]" . " ## $row[type], ";
                foreach($row['department_admins'] as $dk=>$dv) {
                    echo implode(',',$dv).', ';
                }
                echo "<br>\n"; // 1表示班级，2表示年级，3表示学段，4表示校区，5表示学校（根部门）
            }
            foreach ([45,66] as $ck) {
                $r1 = extWework::getEduTabs($ck, $agentId); 
                echo "<b>{$ck} : 学生</b>: student_userid, 名称, pid<br>\n";
                foreach($r1 as $k0=>$row){
                    echo "$row[student_userid] : $row[name] : ".implode(',',$row['department'])." ### ";
                    foreach($row['parents'] as $dk=>$dv) {
                        echo "<br>\n --- " . implode(',',$dv).', ';
                    }
                    echo "<br>\n"; // 1表示班级，2表示年级，3表示学段，4表示校区，5表示学校（根部门）
                }
            }
        }
        
        echo "<hr>";

        if(req('act')=='upd'){
            $r1 = extWework::updContacts('deps', $agentId); dump($r1);
            $r1 = extWework::updContacts('utab', $agentId); dump($r1);
        }else{
            $r1 = extWework::getContacts('deps', $agentId); 
            echo "<b>部门</b>: id, 名称, pid<br>\n";
            foreach($r1 as $k0=>$row){
                echo "$row[id] : $row[name] : $row[parentid]<br>\n";
            }
            $r1 = extWework::getContacts('utab', $agentId); 
            echo "<b>老师</b>: userid, 名称, 部门ids<br>\n";
            foreach($r1 as $k0=>$row){
                echo "$row[userid] : $row[name] : ".implode(',',$row['department'])."<br>\n";
            }
        }   

        die();
    }


    'userid' => 'Tch36',
    'name' => 'Tch2老师',
    'department' => 

    function t02Act(){

        require_once DIR_ROOT."/a3rd/wepv3/example/WxPay.Config.php";
        require_once DIR_ROOT."/a3rd/wepv3/WxPay.funcs.php";
        include_once DIR_WEKIT."/sv-api/api/src/CorpAPI.class.php";
        require_once DIR_WEKIT."/js-sdk/lib/jssdk.php"; 

        $re = extWework::getUser('Peace123', 'AppCS');
        dump($re); die();

    }

    function t01Act(){

        $kidTemp = basKeyid::kidTemp(); dump($kidTemp);
        $ckey = usrMember::getCkey(); dump($ckey);

        include_once(DIR_WEKIT."/sv-api/api/src/CorpAPI.class.php"); 
        $wework = read('wework', 'ex');

        // getData
        $act = $this->ucfg['view'];
        $api = new \CorpAPI($CorpId, $secret);
        if($act=='deps'){
            $res = $api->DepartmentList(null, 1);
        }elseif($act=='utab'){
            //$res = $api->userSimpleList(1, 1, 1);
            $res = $api->UserList(1, 1, 1);

        }
        dump($res);

        die();
    }


    function apisTest($act, $token){ // $reurl, $scope, $state
        if($act=='udeps'){
            $res = extWeedu::getUserDeps($token); 
        }
        if($act=='deplist'){
            $res = extWeedu::getDeplist($token, ''); 
        }
        
        vopApi::view($res, 0);
        if(req('debug')){
            dump($this->re);
        }
        die('.End.');
    }


    function tdir1Act(){
        $retype = req('retype'); $res = $retype ? "retype=$retype" : 'p0=0';
        $pa = req('pa'); $pas = $pa ? "&pa=$pa" : '';
        $pb = req('pa'); $pbs = $pb ? "&pb=$pb" : '';
        $url = surl('login-tget1')."?$res$pas$pbs";
        glbHtml::dallow('*');
        header('Location:'.$url);
        die();
    }
    function tget1Act(){
        $re = $this->re['vars']['null'];
        $re['ucfg'] = $this->ucfg;
        return self::v($re);
    }

    function t2Act(){
        // set^XieYongShun.2020-b2-bewm.f9e6a3^0.0.0
        if(!empty($this->uinfo)){
            $stmp = ['set','XieYongShun.2020-av-hph6.e72f12'];
            $res = $this->saveSet($this->uinfo, $stmp, 'wecdir'); 
            dump($res);
            die('OK!');
        }else{
            die("Error-EmpytUser");
        }
    }

    function testAct(){

        $t = strlen(0);
        dump($t);

        $t = \imcat\usrMember::addUname('o9PAcuAerrObVtcXgKzXllG31twM', 'wechat');
        dump($t);

        $t = \imcat\usrMember::addUname('yufish', 'teeee');
        dump($t);

        $wecfg = wysBasic::getConfig('admin'); 
        $oid = 'oyDK8vjjcn2cFbxMLaMBhKEsYbCk';
        $weu = new wmpUser($wecfg);
        $user = $weu->getUserInfo($oid);
        dump($user);

        #$this->re['vars']['uinfo'] = $this->uinfo;
        #$cval = comConvert::sysRevert($utmp['uid'], 0, 'ck'); 

        die('-test-');
    }

}


    // untie / pptuid
    function untieAct(){
        // db()->table('active_login')->where("ckey='{$this->ckey}'")->delete();
        vopApi::view($this->re['vars']);
    }
    function infoAct(){
        vopApi::view($this->re['vars']);
    }


*/

